package net.boyandi.picback;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Ilya Boyandin
 */
public class Settings {

    private final Set<String> foldersToScan;
    private final Set<String> filetypesToScan;
    private String backupDestinationFolder;
    
    public Settings() {
        foldersToScan = new LinkedHashSet<String>();
        filetypesToScan = new HashSet<String>(Arrays.asList(
                "jpg", "jpeg", "gif", "tif", "tiff", "bmp", "psd", "png", 
                "crw", "nef", "pef",
                "avi", "mpg", "asf", "wmv", "mov"));
    }
    
    public Settings(Settings settings) {
        this.filetypesToScan = new HashSet<String>(settings.filetypesToScan);
        this.foldersToScan = new LinkedHashSet<String>(settings.foldersToScan);
        this.backupDestinationFolder = settings.backupDestinationFolder;
    }

    public void addFolderToScan(String folder) throws IOException {
        foldersToScan.add(new File(folder).getCanonicalPath().toString());
    }
    
    public void removeFolderToScan(String folder) throws IOException {
        foldersToScan.remove(new File(folder).getCanonicalPath().toString());
    }
    
    public List<String> getFoldersToScan() {
        return new ArrayList<String>(foldersToScan);
    }
    
    public List<String> getFiletypesToScan() {
        return new ArrayList<String>(filetypesToScan);
    }

    public void addFiletypeToScan(String extension) throws IOException {
        filetypesToScan.add(extension.toLowerCase());
    }
    
    public void removeFiletypeToScan(String extension) {
        filetypesToScan.remove(extension.toLowerCase());
    }

    public String getBackupDestinationFolder() {
        return backupDestinationFolder;
    }

    public void setBackupDestinationFolder(String backupDestinationFolder) throws IOException {
        this.backupDestinationFolder = new File(backupDestinationFolder).getCanonicalPath().toString();
    }

    public boolean isFiletypeToScan(String ext) {
        if (ext == null  ||  ext.length() == 0) {
            return false;
        }
        return filetypesToScan.contains(ext.toLowerCase());
    }
    
    
}
